package org.share.comm.thread;

/**
 * 线程计数器，提供多线程间计数 用法：ThreadCounter c = ThreadCounter.newThreadCounter();
 * 
 * @author hhm
 *
 */
public class ThreadCounter {

	// 定义该变了需要线程同步
	private volatile int count = 0;

	private ThreadCounter() {
	}

	/**
	 * 获取计数器实例
	 * 
	 * @return
	 */
	public static ThreadCounter newThreadCounter() {
		return new ThreadCounter();
	}

	public void inc() {
		count++;
	}

	public void inc(int val) {
		count += val;
	}

	public void dec() {
		count--;
	}

	public void dec(int val) {
		count -= val;
	}

	public int value() {
		return count;
	}

}
